import os
import sys
import time
import argparse
import multiprocessing
from pyfiglet import Figlet
from rich.console import Console
import telnetlib
import argparse
import threading


lock=threading.Lock()


def install():
    os.system("pip3 install -r plus/apkleaks/requirements.txt --user")
    os.system("pip3 install -r plus/dirsearch/requirements.txt --user")
    os.system("pip3 install -r plus/Finger/requirements.txt --user")
    os.system("pip3 install -r plus/tig/requirements.txt --user")
    os.system("pip3 install -r plus/poc/seeyou/requirements.txt --user")
    os.system("pip3 install -r plus/poc/weaver/equirements.txt --user")

def portscan(ip):
    portlist = [20, 21, 22, 23, 24, 25, 53, 67, 68, 69, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 109, 110, 137, 138, 139, 143, 161, 210, 389, 443, 465, 512, 513, 514, 546, 873, 888, 993,
        994, 995, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1158, 1352, 1433, 1434, 1521, 2049, 2181, 2222, 2888, 3306, 3307, 3308, 3389, 3690, 3700, 3888, 4040, 4100,
        4200, 4444, 4445, 4848, 5000, 5006, 5432, 5601, 5632, 5900, 5901, 5902, 5903, 5904, 5905, 6379, 7001, 7077, 7180, 7181, 7182, 8000, 8480, 8485, 8888, 9000, 9080, 9092, 9300, 9418,
        10000, 10020, 11211, 18080, 19888, 50470, 50475, 60000, 60010, 60020, 60030, 9093, 27017, 27018, 27019, 50010, 50011, 50012, 50013, 50014, 50015, 50016, 50017, 50018, 50019, 50020,
        50021, 50022, 50023, 50024, 50025, 50026, 50027, 50028, 50029, 50030, 50031, 50032, 50033, 50034, 50035, 50036, 50037, 50038, 50039, 50040, 50041, 50042, 50043, 50044, 50045, 50046,
        50047, 50048, 50049, 50050, 50051, 50052, 50053, 50054, 50055, 50056, 50057, 50058, 50059, 50060, 50061, 50062, 50063, 50064, 50065, 50066, 50067, 50068, 50069, 50070, 50071, 50072,
        50073, 50074, 50075, 50076, 50077, 50078, 50079, 50080, 50081, 50082, 50083, 50084, 50085, 50086, 50087, 50088, 50089, 50090, 9094, 9095, 9096, 9097, 9098, 9099, 9100, 9101, 9102,
        9103, 9104, 9105, 9106, 9107, 9108, 9109, 9110, 9111, 9112, 9113, 9114, 9115, 9116, 9117, 9118, 9119, 9120, 9121, 9122, 9123, 9124, 9125, 9126, 9127, 9128, 9129, 9130, 9131, 9132,
        9133, 9134, 9135, 9136, 9137, 9138, 9139, 9140, 9141, 9142, 9143, 9144, 9145, 9146, 9147, 9148, 9149, 9150, 9151, 9152, 9153, 9154, 9155, 9156, 9157, 9158, 9159, 9160, 9161, 9162,
        9163, 9164, 9165, 9166, 9167, 9168, 9169, 9170, 9171, 9172, 9173, 9174, 9175, 9176, 9177, 9178, 9179, 9180, 9181, 9182, 9183, 9184, 9185, 9186, 9187, 9188, 9189, 9190, 9191, 9192,
        9193, 9194, 9195, 9196, 9197, 9198, 9199, 9200, 9081, 9082, 9083, 9084, 9085, 9086, 9087, 9088, 9089, 9090, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009, 8010, 8011, 8012,
        8013, 8014, 8015, 8016, 8017, 8018, 8019, 8020, 8021, 8022, 8023, 8024, 8025, 8026, 8027, 8028, 8029, 8030, 8031, 8032, 8033, 8034, 8035, 8036, 8037, 8038, 8039, 8040, 8041, 8042,
        8043, 8044, 8045, 8046, 8047, 8048, 8049, 8050, 8051, 8052, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, 8062, 8063, 8064, 8065, 8066, 8067, 8068, 8069, 8070, 8071, 8072,
        8073, 8074, 8075, 8076, 8077, 8078, 8079, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099, 8186, 8161, 8363,
        18983, 50003, 61616, 13104
    ]
    lock.acquire()
    print(ip)
    print('PORT     STATE')
    for port in portlist:
        s = telnetlib.Telnet()
        try:
            s.open(ip, port, timeout=2)
            print('%-8s open' % (port))
        except Exception as err:
            pass
        finally:
            s.close()
    lock.release()

def jsscan(xz, url, cookie=None):
    if cookie == '':
        if xz == '1':
            os.system("python3 " + "plus/JSFinder/JSFinder.py -u " + url + " -d -ou report/js_url.txt -os report/js_subdomain.txt")
        if xz == '2':
            os.system("python3 " + "plus/JSFinder/JSFinder.py -f " + url + " -d -ou report/js_url.txt -os report/js_subdomain.txt")
    else:
        if xz == '1':
            os.system("python3 " + "plus/JSFinder/JSFinder.py -u " + url + " -d -ou report/js_url.txt -os report/js_subdomain.txt" + " -c" + cookie)
        if xz == '2':
            os.system("python3 " + "plus/JSFinder/JSFinder.py -f " + url + " -d -ou report/js_url.txt -os report/js_subdomain.txt" + " -c" + cookie)

def finger(xz,input):
    if xz == '1':
        os.system("python3 " + "plus/Finger/Finger.py -u " + input + " -o finger_%Y-%m-%d.html", time.localtime())
    if xz == '2':
        os.system("python3 " + "plus/Finger/Finger.py -f " + input + " -o finger_%Y-%m-%d.html", time.localtime())
    if xz == '3':
        os.system("python3 " + "plus/Finger/Finger.py -i " + input + " -o finger_%Y-%m-%d.html", time.localtime())
    if xz == '4':
        os.system("python3 " + "plus/Finger/Finger.py -if " + input + " -o finger_%Y-%m-%d.html", time.localtime())

def dirsearch(xz, nr, t, report):
    if xz == '1':
        os.system("python3 plus/dirsearch/dirsearch.py -u " + nr + " -t " + t + " -r -i 200,301,302 --format md -o report/dirsearch_" + report +".md")
    if xz == '2':
        os.system("python3 plus/dirsearch/dirsearch.py -l " + nr + " -t " + t + " -r -i 200,301,302 --format md -o report/dirsearch_" + report +".md")

def info_tig(xz, input, report):
    if xz == '1':
        os.system("python3 plus/tig/tig.py -i " + input + "  -o report/tig_" + report +".xlsx")
    if xz == '2':
        os.system("python3 plus/tig/tig.py -f " + input + " -o report/tig_" + report +".xlsx")

def apkleaks(file, report):
    os.system("python3 plus/apkleaks/apkleaks.py -f " + file + "  -o report/apkleaks_" + report + ".txt")

def poc(xz, target_url):
    if xz == '1':
        os.system("python3 plus/poc/seeyou/main.py -u " + target_url)
    if xz == '2':
        os.system("python3 plus/poc/seeyou/main.py -f " + target_url)
    if xz == '3':
        os.system("python3 plus/poc/weaver/main.py -u " + target_url)
    if xz == '4':
        os.system("python3 plus/poc/weaver/main.py -f " + target_url)